Skip to main content

CountrySelector API

CountrySelector is a button component for selecting a country.

Usage Example

Import component

import { CountrySelector } from 'react-international-phone';

Use by providing the selectedCountry and onSelect callback.

<CountrySelector
selectedCountry="ua"
onSelect={({ iso2 }) => setCountry(iso2)}
/>

Output:

Properties

selectedCountry

Selected country (iso2).

  • Type: CountryIso2
  • Default: undefined

onSelect

Callback that calls on country select

  • Type: (country: ParsedCountry) => void
  • Default: undefined

disabled

Is CountrySelector disabled

  • Type: boolean
  • Default: undefined

hideDropdown

Hide dropdown icon and make CountrySelector not clickable

  • Type: boolean
  • Default: undefined

renderButtonWrapper

Render function for custom button wrapper. children and rootProps should be passed to button props. rootProps contains a click handler and properties that are required for accessibility. rootProps should be spread like <button {...rootProps} />

  • Type: (props: { children: React.ReactNode; rootProps: React.ButtonHTMLAttributes<HTMLButtonElement>) => React.ReactNode
  • Default: undefined

Style properties (CountrySelectorStyleProps type)

PropTypeDescription
styleCSSPropertiesCustom styles for CountrySelector container
classNamestringCustom className for CountrySelector container
buttonStyleCSSPropertiesCustom styles for CountrySelector button
buttonClassNamestringCustom className for CountrySelector button
buttonContentWrapperStyleCSSPropertiesCustom styles for CountrySelector button content wrapper
buttonContentWrapperClassNamestringCustom className for CountrySelector button content wrapper
flagStyledropdownStylePropsCustom styles for CountrySelector flag
flagClassNamestringCustom className for CountrySelector flag
dropdownArrowStyledropdownStylePropsCustom styles for CountrySelector dropdown arrow
dropdownArrowClassNamestringCustom className for CountrySelector dropdown arrow
dropdownStylePropsCountrySelectorDropdownStylePropsStyle properties for CountrySelector dropdown

CSS variables

VariableDefault value
--react-international-phone-country-selector-background-color--react-international-phone-background-color
--react-international-phone-country-selector-background-color-hoverwhitesmoke
--react-international-phone-disabled-country-selector-background-color--react-international-phone-disabled-background-color
--react-international-phone-country-selector-border-colorgainsboro
--react-international-phone-country-selector-arrow-size4px
--react-international-phone-country-selector-arrow-color#777
--react-international-phone-disabled-country-selector-arrow-color#999